// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {},

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.RigidBody = this.getComponent(cc.RigidBody);
        let velocity = this.RigidBody;
        velocity.linearVelocity.x = 0;
        velocity.linearVelocity.y = 0;
        this.RigidBody = velocity;
        //
        this.icon = cc.find('icon', this.node);
        this.hp = cc.find('icon/hp', this.node);
    },

    start() {

    },

    initEnemy(id, enemyInfo) {
        //
        this.id = id;
        this.RigidBody.linearVelocity = cc.v2(enemyInfo.xv, 0);
        this.node.setScale(enemyInfo.size);
        //
        this.setHp(enemyInfo.hp);
    },

    setHp(hpNum) {
        this.hp.getComponent(cc.Label).string = hpNum;
    },

    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function (contact, selfCollider, otherCollider) {
        if (selfCollider.tag == ICPC.CONST.TAG.TAG_ENEMY && otherCollider.tag == ICPC.CONST.TAG.TAG_FLY) {
            ICPC.gameDataManager.onGameOver();
        }
    },

    //校正
    update(dt) {
        this.hp.angle = -this.node.angle;
    },
});
